package com.jxd.controller;


import com.jxd.model.Employee;
import com.jxd.model.User;
import com.jxd.service.IEmployeeService;
import com.jxd.service.impl.EmployeeServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequestMapping("/employee")
@RestController
public class EmployeeController {

    @Autowired
    private IEmployeeService employeeService;

    @RequestMapping("/employeeList")
    public Map<String, Object> employeeList(@RequestBody Map<String, String> map) {
        Map<String, Object> map1 = employeeService.getAllEmpList(map);
        return map1;
    }

    @RequestMapping("/addEmp")
    public String addEmp(@RequestBody Employee emp) {
        boolean flag = employeeService.save(emp);
        if (flag) {
            return "success";
        } else {
            return "error";
        }
    }

    @RequestMapping("/updateEmp")
    public String updateEmp(@RequestBody Employee emp) {
        boolean flag = employeeService.updateById(emp);
        if (flag) {
            return "success";
        } else {
            return "error";
        }
    }

    @RequestMapping("/delEmp")
    public String delEmp(@RequestBody List<Integer> empnos) {
        boolean flag = employeeService.removeByIds(empnos);
        if (flag) {
            return "success";
        } else {
            return "error";
        }
    }

    @RequestMapping("/getEmp/{empno}")
    public Employee getEmp(@PathVariable int empno) {
        return employeeService.getById(empno);
    }
}
